package #(package).control;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.generator.TableMeta;
import com.zhangyue.core.annotation.RouteBind;
import #(package).model.#(className);
import #(package).service.#(className)Service;

@RouteBind(path = "/#(smallClassName)")
public class #(className)Control extends Controller{

public static final int PAGE_SIZE = 5;

static #(className)Service service = #(className)Service.#(smallClassName)Service;

public void add(){
service.add(getModel(#(className).class));
list();
}

public void list(){
Page<#(className)> page = service.paginate(getParaToInt("p",1),PAGE_SIZE);
    setAttr("page",page);
    render("#(smallClassName)_list.html");
    }

    public void toAddHtml(){
    render("#(smallClassName)_add.html");
    }

    public void update(){
    service.update(getModel(#(className).class));
    list();
    }

    public void delete(){
    service.delete(getParaToInt("id"));
    list();
    }

    public void findById(){
    int id = getParaToInt("id");
    #(className) #(smallClassName) = service.findById(id);
    setAttr("#(smallClassName)",#(smallClassName));
    render("#(smallClassName)_update.html");
    }

    }
